﻿package mortal.game.manager
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import flash.display.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.mvc.core.*;

    public class SmallIconLayer extends View implements ILayer
    {
        protected var HorizenGap:int = 35;
        private var vcDisplaObject:Vector.<DisplayObject>;
        private var _iconContainer:Sprite;
        protected var _isNeedTween:Boolean = true;
        public var isTween:Boolean = true;

        public function SmallIconLayer()
        {
            this.vcDisplaObject = new Vector.<DisplayObject>;
            tabChildren = false;
            mouseEnabled = false;
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            this._iconContainer = new Sprite();
            this._iconContainer.mouseEnabled = false;
            this.addChild(this._iconContainer);
            return;
        }// end function

        private function tweenAtIndex(param1:int) : void
        {
            var _loc_3:Array = null;
            var _loc_2:int = 0;
            this.vcDisplaObject[_loc_2].y = 0;
            if (param1 == (this.vcDisplaObject.length - 1))
            {
                this.vcDisplaObject[param1].x = this.HorizenGap * param1 + 120;
                TweenMax.to(this.vcDisplaObject[param1], 1, {x:this.HorizenGap * param1});
            }
            else
            {
                _loc_2 = param1;
                while (_loc_2 < this.vcDisplaObject.length)
                {
                    
                    _loc_3 = TweenMax.getTweensOf(this.vcDisplaObject[_loc_2]);
                    if (_loc_3.length)
                    {
                        (_loc_3[0] as TweenMax).kill();
                    }
                    else
                    {
                        this.vcDisplaObject[_loc_2].x = this.HorizenGap * _loc_2 + 120;
                    }
                    TweenMax.to(this.vcDisplaObject[_loc_2], 1, {x:this.HorizenGap * _loc_2});
                    _loc_2++;
                }
            }
            return;
        }// end function

        private function tweenRemoveAtIndex(param1:int) : void
        {
            var _loc_3:Array = null;
            var _loc_2:int = 0;
            if (this.vcDisplaObject.length >= 1)
            {
                this.vcDisplaObject[_loc_2].y = 0;
                _loc_2 = param1;
                while (_loc_2 < this.vcDisplaObject.length)
                {
                    
                    _loc_3 = TweenMax.getTweensOf(this.vcDisplaObject[_loc_2]);
                    if (_loc_3.length)
                    {
                        (_loc_3[0] as TweenMax).kill();
                    }
                    TweenMax.to(this.vcDisplaObject[_loc_2], 1, {x:this.HorizenGap * _loc_2});
                    _loc_2++;
                }
            }
            return;
        }// end function

        public function addPopUp(param1:DisplayObject, param2:Boolean = false) : void
        {
            if (param1 && this.contains(param1) == false)
            {
                this._iconContainer.addChild(param1);
                this.vcDisplaObject.push(param1);
                if (!param2 && this._isNeedTween)
                {
                    this.tweenAtIndex((this.vcDisplaObject.length - 1));
                }
                else
                {
                    param1.x = this.HorizenGap * (this.vcDisplaObject.length - 1);
                }
            }
            return;
        }// end function

        public function centerPopup(param1:DisplayObject) : void
        {
            return;
        }// end function

        public function setPosition(param1:DisplayObject, param2:int, param3:int) : void
        {
            return;
        }// end function

        public function isTop(param1:DisplayObject) : Boolean
        {
            if (this._iconContainer.contains(param1))
            {
                return this._iconContainer.getChildIndex(param1) == (this._iconContainer.numChildren - 1);
            }
            return false;
        }// end function

        public function removePopup(param1:DisplayObject, param2:Boolean = true) : void
        {
            var _loc_3:int = 0;
            if (this._iconContainer.contains(param1))
            {
                this._iconContainer.removeChild(param1);
                _loc_3 = this.vcDisplaObject.indexOf(param1);
                if (_loc_3 >= 0)
                {
                    this.vcDisplaObject.splice(_loc_3, 1);
                }
                this.tweenRemoveAtIndex(_loc_3);
            }
            return;
        }// end function

        public function isPopup(param1:DisplayObject) : Boolean
        {
            return this._iconContainer.contains(param1);
        }// end function

        public function setTop(param1:DisplayObject) : void
        {
            if (this._iconContainer.contains(param1))
            {
                if (this._iconContainer.getChildIndex(param1) != (this._iconContainer.numChildren - 1))
                {
                    this._iconContainer.setChildIndex(param1, (this._iconContainer.numChildren - 1));
                }
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            this.x = (SceneRange.display.width - this.width) / 2;
            this.y = SceneRange.display.height - 120;
            return;
        }// end function

    }
}
